<?php
namespace app\fowl\controller;
use app\fowl\model\ImsXbFindModel;
use cmf\controller\AdminBaseController;
use think\Db;
use app\portal\model\PortalPostModel;

class AdminverifymanagerController extends AdminBaseController
{


    //音频审核
    public function videoverify()
    {
        $param = $this->request->param();

        $categoryId = $this->request->param('category', 0, 'intval');
        $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
        $endTime   = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
        if (!empty($startTime) && !empty($endTime)) {
            $where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['create_time'] = ['<= time', $endTime];
            }
        }
        if(!empty($categoryId)){
            $where['type_id'] = $categoryId;
        }
        $keyword = empty($param['keyword']) ? '' : $param['keyword'];
        if (!empty($keyword)) {
            $where['title'] = ['like', "%$keyword%"];
        }

        $where['status'] = 1;

        $categorys = Db::name('portal_category')->where('parent_id', 4)->field('id,name')->select();
        foreach($categorys as $cv){
            $cvdata[] = '<option value="'.$cv['id'].'">'.$cv['name'].'</option>';
        }
        $cvstr = implode(',', $cvdata);

        $portalPost = new ImsXbFindModel();
        if(isset($where)){
            $result = $portalPost->where($where)->paginate(10);
        }else{
            $result = $portalPost->paginate(10);
        }


        if(!empty($result)){
            foreach($result as $vs){
                $vs->getuserinfo;
                $vs->getcategoryinfo;
            }
        }

//        return json($result->items());
        $item = $result->items();
        if(!empty($item)){
            foreach ($item as $iv){
                //$iv['cover_pic'] = DOMAIN_URL.'upload/'.$iv['cover_pic'];
                $iv['cover_pic'] = cmf_get_image_url(str_replace("\\","/",$iv['cover_pic']));
                $ivs[] = $iv;
            }
        }
        $ivs = isset($ivs) ? $ivs : '';
        //$this->assign('articles', $result->items());
        $this->assign('articles', $ivs);
        $this->assign('page', $result->render());
        $this->assign('categorys', $cvstr);
        return $this->fetch();

    }

    //话题审核
    public function themeverify()
    {
        $param = $this->request->param();

        $categoryId = $this->request->param('category', 0, 'intval');

        $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
        $endTime   = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
        if (!empty($startTime) && !empty($endTime)) {
            $where['published_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['published_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['published_time'] = ['<= time', $endTime];
            }
        }
        if(!empty($categoryId)){
            $where['cate_id'] = $categoryId;
        }

        $keyword = empty($param['keyword']) ? '' : $param['keyword'];
        if (!empty($keyword)) {
            $where['post_title'] = ['like', "%$keyword%"];
        }


        $where['post_status'] = 0;



        $categorys = Db::name('portal_category')->where('parent_id', 5)->field('id,name')->select();
        foreach($categorys as $cv){
            $cvdata[] = '<option value="'.$cv['id'].'">'.$cv['name'].'</option>';
        }
        $cvstr = implode(',', $cvdata);
        $portalPost = new PortalPostModel();
        $result = $portalPost->where($where)->paginate(10);
        if(!empty($result)){
            foreach($result as $vs){
                $vs->categories;
                $vs->getuserinfo;
            }
        }
        $this->assign('articles', $result->items());
        $this->assign('page', $result->render());
        $this->assign('categorys', $cvstr);
        return $this->fetch();
    }

}